package org.example.controller;

import org.example.entity.Department;
import org.example.models.R;
import org.example.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/permission/department")
public class DeptController {
    @Autowired
    private DepartmentService departmentService;
    @RequestMapping("/tree")
    public R tree() {
        return R.success(departmentService.selectDeptTree());
    }

    //   新增
    @PostMapping("/insert")
    public R save(@RequestBody Department department){
        departmentService.save(department);
        return R.success("添加成功");
    }
    //    修改
    @PutMapping("/update")
    public R update(@RequestBody Department department){
        departmentService.updateById(department);
        return R.success("修改成功");
    }
    //    删除
    @DeleteMapping("{id}")
    public R delete(@PathVariable Integer id){
        departmentService.removeById(id);
        return R.success("删除成功");
    }
}
